<?php

defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Based extends Controller
{

    protected $formorders;
    protected $pageurl;
    protected $tbl;
    protected $webtitle;
    protected $delcol;
    protected $ordercol;
    protected $idcol;
    protected $tpl;
    protected $perpage;
    protected $logtitle;
    protected $linkstr;
    protected $lvars;
    protected $avars;
    protected $mvars;
    protected $dvars;
    protected $svars;
    protected $rvars;
    protected $cvars;
    protected $acode;
    protected $mcode;
    protected $dcode;
    protected $rcode;
    protected $arr_cando;
    protected $checkcode;
    protected $logcode;

    public function before()
    {

//        $user = User::instance()->logged_in();
//
//        if (!$user)
//        {
//             $this->request->redirect(Url::base().'admin/login/login?redirect='.$this->request->uri());
//        }
//需要列表的数据字段类别
        $arr_flist = array(2, 3, 4);
        $arr_showdo = Array(
            '' => '查看',
            'A' => '添加',
            'B' => '修改',
            'C' => '删除',
            'D' => '登录',
            'E' => '上架',
            'F' => '转发'
        );



        $logcode['add'] = 'A';
        $logcode['modify'] = 'B';
        $logcode['delete'] = 'C';
        $logcode['login'] = 'D';
        $logcode['onsale'] = 'E';
        $logcode['redict'] = 'F';
        
        $this->logcode = $logcode;



        //$admintype = Ut::instances()->get_uts();

        $adminid = 39;

        $admintype_temp = DB::query(Database::SELECT, 'select b.AUT_ID,b.AUT_NAME from ' . DB::expr('travel_user_uts') . ' a,' . DB::expr('travel_usertypes') . ' b where a.AU_ID=' . $adminid . ' and a.AUT_ID=b.AUT_ID and b.AUT_FLAG=1')->execute()->as_array();

        foreach ($admintype_temp as $value)
        {
            $admintype[] = $value['AUT_ID'];
        }

        $arr_cando = Array();



        if (count($admintype) > 0)
        {
            $arr_cando_temp = Utorder::instances()->get_utorders($admintype);
            foreach ($arr_cando_temp as $value)
            {
                $arr_cando[] = $value['uto_ocode'];
            }
            $this->arr_cando = $arr_cando;
        }
        $formorders_temp = Formorder::instances()->get_formorders();
        foreach ($formorders_temp as $key => $value)
        {
            $value['arr_showdo'] = explode(',', $value['showdo']);
            $arr_class[$value['code']] = $value;
        }

        $this->formorders = $arr_class;
        
        
        if(isset($_GET['code'])){
            $code = $_GET['code'];
        } elseif(isset ($_POST['code'])){
             $code = $_POST['code'];
        }
        
          if(isset($_GET['type'])){
            $type = $_GET['type'];
        } elseif(isset ($_POST['type'])){
             $type = $_POST['type'];
        }

        if (isset($code))
        {
            $checkcode = $code;
            $pagecode = strval($code);
            $this->pageurl = $arr_class[$pagecode]['url'];
            $this->tbl = $arr_class[$pagecode]['tbl'];


            $this->webtitle = $arr_class[$pagecode]['title'];
            $this->delcol = $arr_class[$pagecode]['delcol'];
            $this->ordercol = $arr_class[$pagecode]['ordercol'];
            $this->idcol = $arr_class[$pagecode]['idcol'];
            $this->tpl = $arr_class[$pagecode]['tpl'];
            $this->perpage = $arr_class[$pagecode]['perpage'];
            $this->logtitle = $arr_class[$pagecode]['logtitle'];

           // $this->linkstr = strstr($this->pageurl, "?") ? "&" : "?";
            $this->linkstr = $this->pageurl;
            $this->lvars = $this->linkstr . '/list/';
            $this->avars = $this->linkstr . '/add/';
            $this->mvars = $this->linkstr . '/edit/' . $this->idcol . '/';
            $this->dvars = $this->linkstr . '/delete/?' . $this->idcol . '[]=';
            $this->svars = $this->linkstr . 'dowhat=save';
            $this->rvars = $this->linkstr . 'dowhat=redict';
            $this->cvars = 'onClick="return ConfirmDel();"';
        }


        if (isset($type))
        {

            $checkcode = $checkcode . $type;
            $type = strval($type);
            $typeint = intval($type);
        }

        if (isset($type) || isset($code))
        {
            $this->checkcode = $checkcode;
            $this->acode = $checkcode . $logcode['add'];
            $this->mcode = $checkcode . $logcode['modify'];
            $this->dcode = $checkcode . $logcode['delete'];
            $this->rcode = $checkcode . $logcode['redict'];
        }
    }

}
